home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libstiff
/
error.c.z
/
error.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
3KB
|
133 lines
/*
* error.c
*
* Copyright 1993, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <msgs/uxsgiimpr.h>
#include <stiff.h>
int STerrno;
typedef struct {
char *catToken; /* Message catalog token */
char *defMsg; /* Default message */
} ErrorMessage;
static ErrorMessage errorStrings[] = {
/* STENOMEM */ {
_SGI_LIBSTIFF_STENOMEM,
"Out of memory"
},
/* STENOTFOUND */ {
_SGI_LIBSTIFF_STENOTFOUND,
"Tag not found"
},
/* STEBADTAG */ {
_SGI_LIBSTIFF_STEBADTAG,
"Invalid tag"
},
/* STEBADSTREAM */ {
_SGI_LIBSTIFF_STEBADSTREAM,
"Not a valid tiff stream"
},
/* STENEEDSEEK */ {
_SGI_LIBSTIFF_STENEEDSEEK,
"Non-stream operation"
},
/* STEREADFROMWRITE */ {
_SGI_LIBSTIFF_STEREADFROMWRITE,
"Attempt to read from a write stream"
},
/* STEWRITETOREAD */ {
_SGI_LIBSTIFF_STEWRITETOREAD,
"Attempt to write to a read stream"
},
/* STESYSCALL */ {
_SGI_LIBSTIFF_STESYSCALL,
"System call failed"
},
/* STEBADIMAGE */ {
_SGI_LIBSTIFF_STEBADIMAGE,
"Invalid image file directory"
},
/* STEEOF */ {
_SGI_LIBSTIFF_STEEOF,
"End of stream"
},
};
#define NSTRINGS (sizeof(errorStrings)/sizeof(ErrorMessage))
/*
* int
* STPerror(char *pre)
*
* Description:
* Print an error message to stderr based on the value of
* STerrno. This can be called after a libstiff function has
* failed to present diagnostics to the user. pre will be
* printed first, then a colon and a space, then the error
* message, and then a newline.
*
* Parameters:
* pre prefix to be printed before the error message
*/
void
STPerror(char *pre)
{
if (pre && strlen(pre) != 0) {
(void)fprintf(stderr, "%s: %s\n", pre, STErrorString(STerrno));
} else {
(void)fprintf(stderr, "%s\n", STErrorString(STerrno));
}
}
/*
* char *
* STErrorString(int err)
*
* Description:
* Get a string representation of err. This will only be
* something meaningful if err is in the range of STEBASE to
* STELAST in stiff.h.
*
* Parameters:
* err a valid error code for STerrno
*
* Returns:
* A character string describing the error.
*/
char *
STErrorString(int err)
{
static char buf[100];
if (STEBASE <= err && err < STEBASE + NSTRINGS) {
return gettxt(errorStrings[err - STEBASE].catToken,
errorStrings[err - STEBASE].defMsg);
}
(void)sprintf(buf, gettxt(_SGI_LIBSTIFF_UNKNOWN_ERROR,
"Error code %d"), err);
return buf;
}